/**
 *
 */
var App = (function () {
    // 初始化
    
    function App() { // 属性
        this.paneditor = new PanEditor({ "app": this });
        //
        this.zoom = 1.0;
        this.init();
      
    }
    //
    // 初始化
    App.prototype.init = function (options) {
        var that = this;
        //  $("#workbox").mCustomScrollbar({
        //       axis: "yx" // vertical and horizontal scrollbar
        //  });
        
        // Min, max, start. 
        if ($(".js-min-max-start").length > 0) {
            
            var dec = document.querySelector('.js-min-max-start');
            var initDec = new Powerange(dec, { decimal: true, callback: displayDecimalValue, min: 30, max: 100, start: 53 });
            
            function displayDecimalValue() {
                var zoomNum = dec.value / 100;
                that.setzoom(zoomNum);
                try {
                    that.paneditor.dragresize.zoom = (1.0 / zoomNum);
                   // console.info(that.paneditor.dragresize.zoom);
                }
            catch (ex) {
                    console.info(ex);
                }
            }
        }
        //加载内容
        var panid = that.getquery("panid", location.href);
        this.paneditor.loadeditor({ "panid": panid });
    }
    App.prototype.setzoom = function (zoomNum) {
    //设置真正工作区比例
    
        var $box = $(".workbox");
        var $boxin = $('.workCenter');
        var boxH = $box.height();
        var boxInW = 1920 * zoomNum;
        var boxInH = 1080 * zoomNum;
        var cH = 0;
        if (boxH > boxInH) {
            cH = (boxH - boxInH);
        //$boxin.css({padding:0});
        } else {
            cH = 0;
        //$boxin.css({padding:'10px'});
        }
        
        //$boxin.animate({zoom:zoomNum,left:'50%',top:'50%',marginLeft:-W/2,marginTop:-H/2});
        $boxin.css({ zoom: zoomNum, marginTop: cH });
     
    }
    App.prototype.getquery = function (name, url) {
        // 获取URL地址参数
        
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        if (!url || url == "") {
            url = window.location.href;
        } else {
            url = url.substring(url.indexOf("?"));
        }
        r = url.substr(1).match(reg)
        if (r != null)
            return unescape(r[2]);
        return null;
    }
    // 返回
    return App;
})();

var app;
$(function () {
    app = new App();
})
